package cn.hzc.fortess.core.beetl;

import cn.hzc.fortess.core.shiro.ShiroKit;
import cn.hzc.fortess.core.shiro.ShiroUser;

/**
 * demo:
 *
 * @if(shiro.hasPermission("sam:project:edit")){
 * <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
 * @}
 */
public class ShiroViewExt {

    /**
     * sam:dept:add
     */
    public boolean hasPermission(String authIdentification) {
        ShiroUser shiroUser = ShiroKit.getUser();
        if (shiroUser == null) {
            return false;
        }
        if (shiroUser != null && shiroUser.isAdministrator()) {
            return true;
        }
        return ShiroKit.hasPermission(authIdentification);
    }



    public boolean isAdministrator() {
        return ShiroKit.isAdmin();
    }

    public boolean hasRole(String roleName) {
        return ShiroKit.hasRole(roleName);
    }

    public boolean lacksRole(String roleName) {
        return !hasRole(roleName);
    }

    public boolean hasAnyRoles(String roleNames) {
        return ShiroKit.hasAnyRoles(roleNames.split(ShiroKit.NAMES_DELIMETER));
    }

    public boolean hasAllRoles(String roleNames) {
        return ShiroKit.hasAllRoles(roleNames.split(ShiroKit.NAMES_DELIMETER));
    }




    public boolean lacksPermission(String authIdentification) {
        return ShiroKit.lacksPermission(authIdentification);
    }

    public boolean authenticated() {
        return ShiroKit.isAuthenticated();
    }


    public boolean notAuthenticated() {
        return !authenticated();
    }


}
